import request from "@/utils/request"

const COMPANY_BASE_URL = "/api/object/com.siline.chimes/ChimesCompany"

class CompanyAPI {
  /** 获取公司分页数据 */
  static getPage(data: QueryCondition = {}) {
    return request<any, ResponseData<PageResult<CompanyVO[]>>>({
      url: `${COMPANY_BASE_URL}/paged_query`,
      method: "post",
      data,
    })
  }

  /** 获取公司下拉数据源 */
  static getOptions(data: QueryCondition = {}) {
    return request<any, ResponseData<OptionType[]>>({
      url: `${COMPANY_BASE_URL}/query`,
      method: "post",
      data,
    })
  }

  /** 获取公司数据列表 */
  static query(data: QueryCondition = {}) {
    return request<any, ResponseData<CompanyVO[]>>({
      url: `${COMPANY_BASE_URL}/query`,
      method: "post",
      data,
    })
  }

  /**
   * 获取公司表单数据
   *
   * @param id 公司ID
   * @returns 公司表单数据
   */
  static getFormData(id: number) {
    return request<any, ResponseData<CompanyForm>>({
      url: `${COMPANY_BASE_URL}/select/${id}`,
      method: "get",
    })
  }

  /** 添加公司 */
  static add(data: CompanyForm) {
    return request<any, ResponseData<CompanyForm>>({
      url: `${COMPANY_BASE_URL}/insert`,
      method: "post",
      data: data,
    })
  }

  /**
   * 更新公司
   *
   * @param data 公司表单数据
   */
  static update(data: CompanyForm) {
    return request<any, ResponseData<CompanyForm>>({
      url: `${COMPANY_BASE_URL}/update`,
      method: "post",
      data: data,
    })
  }

  /**
   * 根据条件批量删除公司
   *
   * @param data
   */
  static deleteBy(data: QueryCondition) {
    return request({
      url: `${COMPANY_BASE_URL}/delete_by`,
      method: "post",
      data: data,
    })
  }
}
export default CompanyAPI

/** 公司分页对象 */
export interface CompanyVO {
  address?: string
  area_code?: string
  brief?: string
  company_code?: string
  company_id?: number
  company_name?: string
  contact_name?: string
  contact_no?: string
  create_time?: Date
  emails?: string
  full_city?: string
  legal_person?: string
  register_name?: string
  register_openid?: string
  register_unionid?: string
  unform_code?: string
  update_time?: Date
}

/** 公司表单对象 */
export interface CompanyForm {
  company_id?: number
  company_name?: string
  company_code?: string
  area_code?: string
  full_city?: string
  unform_code?: string
  legal_person?: string
  contact_name?: string
  address?: string
  contact_no?: string
  brief?: string
  emails?: string
}
